package com.lookwider.services.impl;

import com.lookwider.beans.JobCategory;
import com.lookwider.beans.Place;
import com.lookwider.beans.User;
import com.lookwider.services.UserService;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

import static com.google.common.collect.Lists.newArrayList;

@Service
public class UserServiceImpl implements UserService {

    @Override
    public User findTopFor( JobCategory jobCategory ) {
        return getUser( jobCategory, new Long(0) );
    }

    private User getUser( JobCategory jobCategory, Long karma ) {
        User user = new User();
        user.setId( 4321 );
        user.setCreatedDate(new Date());
        user.setJobCategory(jobCategory);
        user.setLastLogin(new Date());
        user.setLastname("Pupkin");
        user.setName("Vasily");
        user.setKarma( karma > 0 ? karma : 999999 );
        Place place = new Place();
        place.setId( 987 );
        place.setName( "Restaran 'Y Morya'" );
        place.setJobCategory( jobCategory );
        user.setPlace( place );
        return user;
    }

    @Override
    public List<User> findBatchMaxKarma(JobCategory category, Long karma) {
        List<User> users = newArrayList();
        for ( int i = 0 ; i < 4; i++) {
            users.add( getUser( category, ( karma > 0 ? karma - 10 : 0 ) ) );
        }
        return users;
    }
}
